<?php 

require_once(dirname(__FILE__).'/../lib/BasesfCMSfrontActions.class.php');

class sfCMSfrontActions extends BasesfCMSfrontActions
{
    public function executeShowContent(sfWebRequest $request)
    {
        //var_dump($request->getParameter('id'));exit;
        $this->content = ContentPeer::retrieveByPK($request->getParameter('id'));
        append_title( $this->content->getTitle() );
    }
    
    public function executeShowCategory(sfWebRequest $request)
    {
        
    }


    public function executeSitemap(sfWebRequest $request)
    {
        //throw new sfException('The sitemap is not yet implemented');
        append_title(__('Site map'));

        $this->menu_list = MenuPeer::getSiteMapMenus();
    }

    public function executeContactUs(sfWebRequest $request)
    {
        
        
        append_title(__('Contact us'));

        $this->form = new ContactForm();
        if($request->isMethod('post')){

            $this->form->bind($request->getParameter($this->form->getName()));

            if($this->form->isValid()){
                $this->getUser()->setFlash('notice','Message sent successfully!');

                nahoMail::send(
                'contact us form -- '.ContactForm::$subjects[$this->form->getValue('subject')]
                , $this->form->getValue('message')
                , CMS_globals::get_admin_attr('admin_mail')
                , array('from'=>$this->form->getValue('name').' <'.$this->form->getValue('email').'>')
                );

                $this->getContext()->getConfiguration()->loadHelpers('Partial');

                $body = nahoMail::getBody('partial', 'sfCMSfront/mail_body_contact_your_mesg_sent',array('values'=>$this->form->getValues()));
                nahoMail::send(
                'contact us form -- '.ContactForm::$subjects[$this->form->getValue('subject')]
                , $body
                , $this->form->getValue('email')
                );


            }else{
                $this->getUser()->setFlash('error','please fix errors below');
            }
        }
    }
    
    public function executeChange_pass(sfWebRequest $request){
        $this->form = new changePasswordForm();
        
        if($request->isMethod('post')){
            $this->form->bind($request->getParameter($this->form->getName()));
            if($this->form->isValid()){
                $this->getUser()->setFlash('notice','Password changed succcessfully');
                //$this->form->save();
                $usr = $this->getUser()->getGuardUser();
                /*@var $usr sfGuardUser*/
                if( $usr ) {
                    $usr->setPassword( $this->form->getValue('newpassword') );
                    $usr->save();
                }
            }else{
                $this->getUser()->setFlash('error','somthing wrong happend please fix below');
            }
        }
    }
    
}
